package com.groupsix.service.impl;

import com.groupsix.entity.Dormrepair;
import com.groupsix.mapper.DormrepairMapper;
import com.groupsix.service.DormRepairService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 宿舍维修业务逻辑接口实现类
 * @date 2021/10/17 15:44
 */
@Service
public class DormRepairServiceImpl implements DormRepairService {
    // classDao
    @Autowired
    private DormrepairMapper dormrepairMapper;

    //分页查询
    @Override
    public PageInfo findPageInfo(Integer dId, String dDormbuilding, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = dormrepairMapper.totalCount(dId,dDormbuilding);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示宿舍信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormrepair> dormRepairList =	dormrepairMapper.getDormRepairList(dId,dDormbuilding,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(dormRepairList);
        }
        return pi;
    }

    @Override
    public List<Dormrepair> getAll(){
        List<Dormrepair> dormRepairList = dormrepairMapper.getAll();
        return dormRepairList;
    }

    //添加宿舍信息
    @Override
    public int addDormRepair(Dormrepair dormrepair) {
        return dormrepairMapper.addDormRepair(dormrepair);
    }

    //通过id删除宿舍信息
    @Override
    public int deleteDormRepair(Integer rId) {
        return dormrepairMapper.deleteDormRepair(rId);
    }

    //修改宿舍信息
    @Override
    public int updateDormRepair(Dormrepair dormrepair) {
        return dormrepairMapper.updateDormRepair(dormrepair);
    }

    @Override
    public Dormrepair findDormRepairById (Integer rId){
        Dormrepair d = dormrepairMapper.findDormRepairById(rId);
        return  d;
    }

}
